; (function () {
  var loginView = null;// 设置变量用于存放对话框DOM

  function loginRegisterAction(event) {
    event.preventDefault();// 阻止a标签的默认形为
    // loginView = null 
    if (!loginView) { // 如果对话框没有显示出来
      var type = event.target.dataset.type;
      // console.log(type, event);
      loginView = new pageTools.Login(type == 'login', 'body', function () {
        loginView = null;
      })
    }
  }
  // mock导航栏JSON数据
  var datas = [
    {
      id: '001',
      title: '首页',
      url: 'http://www.tugoo.net/tongcheng.aspx',
      imageUrl: ''
    },
    {
      id: '002',
      title: '土购生鲜',
      url: 'http://www.tugoo.net/news.aspx',
      imageUrl: ''
    },
    {
      id: '003',
      title: '新闻资讯',
      url: 'http://www.tugoo.net/tongcheng.aspx',
      imageUrl: ''
    },
    {
      id: '004',
      title: '特价商品',
      url: 'http://www.tugoo.net/tongcheng.aspx',
      imageUrl: 'http://www.tugoo.net/template/platform_default/new/images/hot.png'
    },
    {
      id: '005',
      title: '企业直采',
      url: 'http://www.tugoo.net/tongcheng.aspx',
      imageUrl: ''
    },
    {
      id: '006',
      title: '商家入驻',
      url: 'http://www.tugoo.net/tongcheng.aspx',
      imageUrl: ''
    }
  ]
  // 导航栏实例化处理
  function nav() {
    new pageTools.Nav('.nav_container', datas, function () {
      console.log(text);
    })
  }
  // 注册登录
  function loginRegister() {
    $('.login').click(loginRegisterAction);
    $('.register').click(loginRegisterAction);
  }
  // 轮播图
  function banner() {
    var mySwiper = new Swiper('.swiper-container', {
      loop: true, // 循环模式选项
      // 自动播放
      autoplay: {
        delay: 3000,
        stopOnLastSlide: false,
        disableOnInteraction: true
      },
      // 如果需要分页器
      pagination: {
        el: '.swiper-pagination',
        clickable: true
      },
      // 如果需要前进后退按钮
      navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
      }
    })
  }
  // 分类导航数据mock（模拟）
  var category = [
    {
      title: "水果蔬菜",
      des: [
        { title: "苹果" },
        { title: "脐橙" },
        { title: "榴莲" },
        { title: "有机蔬菜" },
        { title: "圣女果" }
      ]
    },
    {
      title: "休闲食品",
      des: [
        { title: "葡萄干" },
        { title: "开心果" },
        { title: "曲奇" },
        { title: "月饼" }]
    },
    {
      title: "生鲜",
      des: [
        { 
          title: "鱿鱼"
        },
        { title: "甲鱼" },
        { title: "帝王蟹" },
        { title: "澳龙" }
      ]
    },
    {
      title: "茶叶冲饮",
      des: [
        { title: "普洱茶" },
        { title: "红茶" },
        { title: "斯里兰卡茶" },
        { title: "柚子茶" }
      ]
    }
  ];
  // 分类导航
  function categoryNav(){
    new pageTools.Category('.category-nav', category, function(res){
      console.log(res);
    })
  }
  // 商品列表数据mock
  var goods = [
    {
      title:"水果蔬菜",
      addr:"https://oss-img-mro.yzw.cn/mro-item-sku/ee7c6052307f6bc5cea7ffa3d509ffee.png?x-oss-process=image/auto-orient,1/interlace,1/quality,Q_90/resize,m_pad,w_360",
      des:[
        {
          title:"邮政包邮！【土购网】赣南脐橙5斤试吃装 正宗赣南脐橙 酸甜可口",
          price:"19.90",
          name:"正宗赣南脐橙",
          image:"https://oss-img-mro.yzw.cn/mro-item-sku/b8d8a8fc31b8c16a638162848d59632a.jpg?x-oss-process=image/auto-orient,1/interlace,1/quality,Q_90/resize,m_pad,w_360"
        },
        {
          title:"九山生姜 2.5kg",
          price:"38.90",
          name:"九山生姜 2.5kg",
          image:"http://www.tugoo.net/UploadFile/product/317/201712301024359452_352_352.jpg"
        },
        {
          title:"九山生姜 2.5kg",
          price:"38.90",
          name:"九山生姜 2.5kg",
          image:"http://www.tugoo.net/UploadFile/product/317/201712301024359452_352_352.jpg"
        },
        {
          title:"邮政包邮！【土购网】赣南脐橙5斤试吃装 正宗赣南脐橙 酸甜可口",
          price:"19.90",
          name:"正宗赣南脐橙",
          image:"http://www.tugoo.net/UploadFile/product/317/201711141559442018_352_352.png"
        },
        {
          title:"九山生姜 2.5kg",
          price:"38.90",
          name:"九山生姜 2.5kg",
          image:"http://www.tugoo.net/UploadFile/product/317/201712301024359452_352_352.jpg"
        },
        {
          title:"九山生姜 2.5kg",
          price:"38.90",
          name:"九山生姜 2.5kg",
          image:"http://www.tugoo.net/UploadFile/product/317/201712301024359452_352_352.jpg"
        },
        {
          title:"邮政包邮！【土购网】赣南脐橙5斤试吃装 正宗赣南脐橙 酸甜可口",
          price:"19.90",
          name:"正宗赣南脐橙",
          image:"http://www.tugoo.net/UploadFile/product/317/201711141559442018_352_352.png"
        },
        {
          title:"九山生姜 2.5kg",
          price:"38.90",
          name:"九山生姜 2.5kg",
          image:"http://www.tugoo.net/UploadFile/product/317/201712301024359452_352_352.jpg"
        },
        {
          title:"九山生姜 2.5kg",
          price:"38.90",
          name:"九山生姜 2.5kg",
          image:"http://www.tugoo.net/UploadFile/product/317/201712301024359452_352_352.jpg"
        }
      ]
    },
    {
      title:"生鲜",
      addr:"http://www.tugoo.net/UploadFile/ggs/201605261835490333.jpg",
      des:[
        {
          title:"1号鲜客 挪威冰鲜三文鱼刺身400g",
          price:"79.00",
          name:"挪威冰鲜三文鱼刺身400g",
          image:"http://www.tugoo.net/UploadFile/product/317/201707081107044936_352_352.jpg"
        },
        {
          title:"大连特产鲜活大鲍鱼鲜活海鲜水产活鲜海产",
          price:"128.00",
          name:"大连特产鲜活大鲍鱼",
          image:"http://www.tugoo.net/UploadFile/product/651/201503250925538825_352_352.jpg"
        },
        {
          title:"大连特产鲜活大鲍鱼鲜活海鲜水产活鲜海产",
          price:"128.00",
          name:"大连特产鲜活大鲍鱼",
          image:"http://www.tugoo.net/UploadFile/product/651/201503250925538825_352_352.jpg"
        },
        {
          title:"1号鲜客 挪威冰鲜三文鱼刺身400g",
          price:"79.00",
          name:"挪威冰鲜三文鱼刺身400g",
          image:"http://www.tugoo.net/UploadFile/product/317/201707081107044936_352_352.jpg"
        },
        {
          title:"大连特产鲜活大鲍鱼鲜活海鲜水产活鲜海产",
          price:"128.00",
          name:"大连特产鲜活大鲍鱼",
          image:"http://www.tugoo.net/UploadFile/product/651/201503250925538825_352_352.jpg"
        },
        {
          title:"大连特产鲜活大鲍鱼鲜活海鲜水产活鲜海产",
          price:"128.00",
          name:"大连特产鲜活大鲍鱼",
          image:"http://www.tugoo.net/UploadFile/product/651/201503250925538825_352_352.jpg"
        },
        {
          title:"1号鲜客 挪威冰鲜三文鱼刺身400g",
          price:"79.00",
          name:"挪威冰鲜三文鱼刺身400g",
          image:"http://www.tugoo.net/UploadFile/product/317/201707081107044936_352_352.jpg"
        },
        {
          title:"大连特产鲜活大鲍鱼鲜活海鲜水产活鲜海产",
          price:"128.00",
          name:"大连特产鲜活大鲍鱼",
          image:"http://www.tugoo.net/UploadFile/product/651/201503250925538825_352_352.jpg"
        },
        {
          title:"大连特产鲜活大鲍鱼鲜活海鲜水产活鲜海产",
          price:"128.00",
          name:"大连特产鲜活大鲍鱼",
          image:"http://www.tugoo.net/UploadFile/product/651/201503250925538825_352_352.jpg"
        },
        {
          title:"1号鲜客 挪威冰鲜三文鱼刺身400g",
          price:"79.00",
          name:"挪威冰鲜三文鱼刺身400g",
          image:"http://www.tugoo.net/UploadFile/product/317/201707081107044936_352_352.jpg"
        },
        {
          title:"大连特产鲜活大鲍鱼鲜活海鲜水产活鲜海产",
          price:"128.00",
          name:"大连特产鲜活大鲍鱼",
          image:"http://www.tugoo.net/UploadFile/product/651/201503250925538825_352_352.jpg"
        },
        {
          title:"大连特产鲜活大鲍鱼鲜活海鲜水产活鲜海产",
          price:"128.00",
          name:"大连特产鲜活大鲍鱼",
          image:"http://www.tugoo.net/UploadFile/product/651/201503250925538825_352_352.jpg"
        }
      ]
    }
  ]
  // console.log(goods);
  // 实例化商品类
  function goodsList(){
    new pageTools.Goods('.main-container',goods,function(){
      console.log('goods');
    })
  }
  // 主函数(入口函数)
  function main() {
    loginRegister();
    nav();
    banner();
    categoryNav();
    goodsList();
  }
  main();
})();